#define DEBUG
#include <cstdio>
#define MAXN 50000

using namespace std;

int main() {
#ifdef DEBUG
  freopen("0.in", "r", stdin);
  freopen("0_bf.out", "w", stdout);
#endif

  static char word[MAXN+1][5];
  int n, d;
  scanf("%d %d", &n, &d);
  for (int i=1; i<=n; i++) {
    scanf("%s", word[i]);
  }

  int ans=0;
  for (int i=1; i<=n; i++) {
    for (int j=i+1; j<=n; j++) {
      int t=0;
      for (int k=0; k<4; k++) {
	t+=word[i][k]!=word[j][k];
      }
      ans += t==d;
    }
  }
  printf("%d", ans);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
